package com.zhuojy.equity.mall.admin.web.controller.salary;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhuojy.equity.mall.admin.common.entity.TPosition;
import com.zhuojy.equity.mall.admin.common.entity.bo.salary.*;
import com.zhuojy.equity.mall.admin.common.entity.po.THolidayPo;
import com.zhuojy.equity.mall.admin.common.entity.po.salary.*;
import com.zhuojy.equity.mall.admin.common.entity.vo.salary.SalaryEchoVO;
import com.zhuojy.equity.mall.admin.common.entity.vo.salary.TSalaryVO;
import com.zhuojy.equity.mall.admin.common.entity.vo.salary.TUserArchivesVO;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.service.salary.TSalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author chen
 * @version 1.0
 * @description: 薪资模块
 * @date 2024/3/27 16:06
 */
@RequestMapping("salary")
@RestController
@RequiredArgsConstructor
@Api(tags = "薪资模块")
public class TSalaryController {

    private final TSalaryService tSalaryService;

    /**
     * @description: 添加薪资方案
     * @author Mr.chen
     * @date 2024-03-27 16:03:47
     * @version 1.0
     */
    @PostMapping("addPayrollProposal")
    @ApiOperation(value = "添加薪资",httpMethod = "POST",notes = "添加薪资")
    public ResultEntity addPayrollProposal(TSalaryPO tSalaryPO,
                                           TaxCalculationRulesPO taxCalculationRulesPO,
                                           StandardPayrollRulesPO standardPayrollRulesPO,
                                           SickLeaveRulesPO sickLeaveRulesPO,
                                           RulesForTheDistributionOfAttendanceAwardsPO rulesForTheDistributionOfAttendanceAwardsPO,
                                           PersonalLeaveRulesPO personalLeaveRulesPO,
                                           OvertimeRulesPO overtimeRulesPO,
                                           LateChargeRulesBO lateChargeRulesBO,
                                           LateArrivalRulesPO lateArrivalRulesPO,
                                           EarlyRefundDeductionRulesBO earlyRefundDeductionRulesBO,
                                           AbsenteeismDeductionRulesPO absenteeismDeductionRulesPO,
                                           HttpServletRequest request){
        try {
            System.out.println("tSalaryPO"+tSalaryPO);
//        System.out.println("taxCalculationRulesPO"+taxCalculationRulesPO);
//        System.out.println("standardPayrollRulesPO"+standardPayrollRulesPO);
//        System.out.println("sickLeaveRulesPO"+sickLeaveRulesPO);
//        System.out.println("rulesForTheDistributionOfAttendanceAwardsPO"+rulesForTheDistributionOfAttendanceAwardsPO);
//        System.out.println("personalLeaveRulesPO"+personalLeaveRulesPO);
//        System.out.println("overtimeRulesPO"+overtimeRulesPO);
//        System.out.println("lateChargeRulesPO"+lateChargeRulesBO);
//        System.out.println("lateArrivalRulesPO"+lateArrivalRulesPO);
//        System.out.println("earlyRefundDeductionRulesPO"+earlyRefundDeductionRulesBO);
//        System.out.println("absenteeismDeductionRulesPO"+absenteeismDeductionRulesPO);
            tSalaryService.addPayrollProposal(tSalaryPO,
                    taxCalculationRulesPO,
                    standardPayrollRulesPO,
                    sickLeaveRulesPO,
                    rulesForTheDistributionOfAttendanceAwardsPO,
                    personalLeaveRulesPO,
                    overtimeRulesPO,
                    lateChargeRulesBO,
                    lateArrivalRulesPO,
                    earlyRefundDeductionRulesBO,
                    absenteeismDeductionRulesPO,request);
            return ResultEntity.OK("新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("新增失败");
        }
    }
    /**
     * @description: 修改薪资方案
     * @author Mr.chen
     * @date 2024-04-06 11:04:15
     * @version 1.0
     */
    @PostMapping("updateSalary")
    @ApiOperation(value = "修改薪资方案",httpMethod = "POST",notes = "修改薪资方案")
    public ResultEntity updateSalary(TSalaryPO tSalaryPO,
                                           TaxCalculationRulesPO taxCalculationRulesPO,
                                           StandardPayrollRulesPO standardPayrollRulesPO,
                                           SickLeaveRulesPO sickLeaveRulesPO,
                                           RulesForTheDistributionOfAttendanceAwardsPO rulesForTheDistributionOfAttendanceAwardsPO,
                                           PersonalLeaveRulesPO personalLeaveRulesPO,
                                           OvertimeRulesPO overtimeRulesPO,
                                           LateChargeRulesBO lateChargeRulesBO,
                                           LateArrivalRulesBO lateArrivalRulesBO,
                                           EarlyRefundDeductionRulesBO earlyRefundDeductionRulesBO,
                                           AbsenteeismDeductionRulesPO absenteeismDeductionRulesPO,
                                           HttpServletRequest request){
        System.out.println("tSalaryPO"+tSalaryPO);
        System.out.println("taxCalculationRulesPO"+taxCalculationRulesPO);
        System.out.println("standardPayrollRulesPO"+standardPayrollRulesPO);
        System.out.println("sickLeaveRulesPO"+sickLeaveRulesPO);
        System.out.println("rulesForTheDistributionOfAttendanceAwardsPO"+rulesForTheDistributionOfAttendanceAwardsPO);
        System.out.println("personalLeaveRulesPO"+personalLeaveRulesPO);
        System.out.println("overtimeRulesPO"+overtimeRulesPO);
        System.out.println("lateChargeRulesPO"+lateChargeRulesBO);
        System.out.println("lateArrivalRulesPO"+lateArrivalRulesBO);
        System.out.println("earlyRefundDeductionRulesPO"+earlyRefundDeductionRulesBO);
        System.out.println("absenteeismDeductionRulesPO"+absenteeismDeductionRulesPO);
        try {
            tSalaryService.updateSalary(tSalaryPO,
                    taxCalculationRulesPO,
                    standardPayrollRulesPO,
                    sickLeaveRulesPO,
                    rulesForTheDistributionOfAttendanceAwardsPO,
                    personalLeaveRulesPO,
                    overtimeRulesPO,
                    lateChargeRulesBO,
                    lateArrivalRulesBO,
                    earlyRefundDeductionRulesBO,
                    absenteeismDeductionRulesPO,request);


            return ResultEntity.OK("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("修改异常");
        }
    }
    /**
     * @description: 获取部门列表
     * @author Mr.chen
     * @date 2024-04-01 14:04:25
     * @version 1.0
     */
    @GetMapping("getDeptList")
    @ApiOperation(value = "获取部门列表",httpMethod = "GET",notes = "获取部门列表")
    public ResultEntity getDeptList(){
        try {
            List<TPosition> list = tSalaryService.getDeptList();
            return ResultEntity.OK(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查询失败");
        }
    }
    /**
     * @description: 获取假期类型列表
     * @return:
     * @return com.zhuojy.equity.mall.admin.common.pojo.ResultEntity
     * @author chen
     * @date: 2024-04-02 19:04:00
     */
    @GetMapping("getHolidayList")
    @ApiOperation(value = "获取假期类型列表",httpMethod = "GET",notes = "获取假期类型列表")
    public ResultEntity getHolidayList(){
        try {
            List<THolidayPo> list = tSalaryService.getHolidayList();
            return ResultEntity.OK(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查询失败");
        }
    }
    /**
     * @description: 获取薪资方案列表
     * @return:
     * @author chen
     * @date: 2024-04-02 19:04:00
     */
    @PostMapping("getSalaryList")
    @ApiOperation(value = "获取薪资方案列表",httpMethod = "POST",notes = "获取薪资方案列表")
    public ResultEntity getSalaryList(@RequestBody TSalaryBO tSalaryBO){
        try {
            Map map = tSalaryService.getSalaryList(tSalaryBO);
            return ResultEntity.OK(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查询失败");
        }
    }
    @GetMapping("findSalary")
    @ApiOperation(value = "回显薪资方案",httpMethod = "GET",notes = "回显薪资方案")
    public ResultEntity findSalary(@RequestParam(value = "id") Long id){
        try {
            System.out.println(id);
            SalaryEchoVO salaryEchoVO = tSalaryService.findSalary(id);

            return ResultEntity.OK(salaryEchoVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("Error finding salary");
        }
    }
    @GetMapping("stopSalary")
    @ApiOperation(value = "停用薪资方案",httpMethod = "GET",notes = "停用薪资方案")
    public ResultEntity stopSalary(@RequestParam(value = "id") Long id){
        try {
            System.out.println(id);
            tSalaryService.stopSalary(id);

            return ResultEntity.OK("停用成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("Error stop salary");
        }
    }
    @GetMapping("deleteSalary")
    @ApiOperation(value = "停用薪资方案",httpMethod = "GET",notes = "停用薪资方案")
    public ResultEntity deleteSalary(@RequestParam(value = "id") Long id){
        try {
            System.out.println(id);
            tSalaryService.deleteSalary(id);
            return ResultEntity.OK("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("Error delete salary");
        }
    }
    @GetMapping("getSalaryCount")
    @ApiOperation(value = "统计薪资人数",httpMethod = "GET",notes = "统计薪资人数")
    public ResultEntity getSalaryCount(@RequestParam(value = "id") Long id){
        try {

            Map map = tSalaryService.getSalaryCount(id);
            return ResultEntity.OK(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("Error delete salary");
        }
    }
    @GetMapping("findNotAddedUserList")
    @ApiOperation(value = "查询未添加人员",httpMethod = "GET",notes = "查询未添加人员")
    public ResultEntity findNotAddedUserList(@RequestParam(value = "id") Long id){
        try {
            List<TUserArchivesVO> list = tSalaryService.findNotAddedUserList(id);
            return ResultEntity.OK(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查询失败");
        }
    }
    @PostMapping("addPeople")
    @ApiOperation(value = "添加人员",httpMethod = "POST",notes = "添加人员")
    public ResultEntity addPeople(@RequestBody AddPeopleBO addPeopleBO){
        try {
            tSalaryService.addPeople(addPeopleBO);
            return ResultEntity.OK("添加人员成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("添加人员失败!!!");
        }
    }

    @PostMapping("findSalaryByIdList")
    @ApiOperation(value = "查询添加人员",httpMethod = "POST",notes = "查询添加人员")
    public ResultEntity findSalaryByIdList(@RequestBody TUserArchivesBO tUserArchivesBO){
        try {
            Map map=tSalaryService.findSalaryByIdList(tUserArchivesBO);
            return ResultEntity.OK(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查询人员失败!!!");
        }
    }

    @PostMapping("removePeople")
    @ApiOperation(value = "查询添加人员",httpMethod = "POST",notes = "查询添加人员")
    public ResultEntity removePeople(@RequestBody TUserArchivesBO tUserArchivesBO){
        try {
            tSalaryService.removePeople(tUserArchivesBO);
            return ResultEntity.OK("移除人员成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("移除人员失败!!!");
        }
    }
    @PostMapping("accounting")
    @ApiOperation(value = "核算薪资方案",httpMethod = "POST",notes = "核算薪资方案")
    public ResultEntity accounting(@RequestBody TSalaryPO tSalaryPO){
        try {
            tSalaryService.update(Wrappers.lambdaUpdate(TSalaryPO.class).eq(TSalaryPO::getId,tSalaryPO.getId()).set(TSalaryPO::getState,tSalaryPO.getState()));
            return ResultEntity.OK("核算成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("核算失败!!!");
        }
    }

    @PostMapping("getPayrollList")
    @ApiOperation(value = "查询工资发放实体类",httpMethod = "POST",notes = "查询工资发放实体类")
    public ResultEntity getPayrollList(@RequestBody PaySlipsBO paySlipsBO){
        try {
            Map map = tSalaryService.getPayrollList(paySlipsBO);
            return ResultEntity.OK(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查询工资发放失败!!!");
        }
    }
    @GetMapping("getPayrollCount")
    @ApiOperation(value = "获取工资条发送人数",httpMethod = "GET",notes = "获取工资条发送人数")
    public ResultEntity getPayrollCount(@RequestParam(value = "id") Long id){
        try {
            Map map = tSalaryService.getPayrollCount(id);
            return ResultEntity.OK(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("查询人数失败!!!");
        }
    }
    @PostMapping("getPayrollPeopleList")
    @ApiOperation(value = "获取工资条发送人数列表",httpMethod = "POST",notes = "获取工资条发送人数列表")
    public ResultEntity getPayrollPeopleList(@RequestBody PayrollBO payrollBO){
        try {
            Map map = tSalaryService.getPayrollPeopleList(payrollBO);
            return ResultEntity.OK(map);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("获取工资条发送人数列表异常!!!");
        }
    }
}
